package com.allwees.bs.module.pms.mq.listener;

import com.allwees.bs.core.model.product.mq.event.model.ProductStatItemInfo;
import com.allwees.bs.module.pms.service.GeneralProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 *
 *
 * @author yangylsky
 * @since 2020-03-21
 *
 */
@Slf4j
@Component
@RabbitListener(queues = "q.Product.ProductStatItem")
public class ProductStatItemListener {
	@Autowired
	private GeneralProductService generalProductService;

	@RabbitHandler
	public void processMessage(ProductStatItemInfo info) {

		log.info("receive message product stat item put on:{info: {}}", info);

		switch(info.getType()) {
			case ADD_COLLECTIONS:
				//com.allwees.bs.c.module.user.service.impl.CollectionServiceImpl.collProduct(String, String) 已更新
				generalProductService.addCollections(info.getUuid());
				break;
			case REMOVE_COLLECTIONS:
				//com.allwees.bs.c.module.user.service.impl.CollectionServiceImpl.cancelCollProduct(String, EntityIdsVo) 已更新
				generalProductService.removeCollections(info.getUuid());
				break;
			case SHARE:
				generalProductService.addShares(info.getUuid());
				break;
			case SALE:
				//com.allwees.bs.c.module.product.repository.ProductRepository.updateAppendTotalSales(String, Integer) 已更新
				generalProductService.addSales(info.getUuid(), info.getCount());
				break;
			case REFUND:
				generalProductService.addRefunds(info.getUuid(), info.getCount());
				break;
			case REVIEW:
				//com.allwees.bs.c.module.product.repository.ProductRepository.updateAppendTotalReviews(String) 已更新
				generalProductService.addReviews(info.getUuid());
				break;
			case VIEW:
				generalProductService.addViews(info.getUuid());
				break;
			default:
				break;
		}
	}
}
